package cn.iocoder.yudao.module.biz.dal.mysql.risk.controlMeasures;

import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.biz.controller.admin.risk.controlMeasures.vo.BizControlMeasuresExportReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.risk.controlMeasures.vo.BizControlMeasuresPageReqVO;
import cn.iocoder.yudao.module.biz.controller.admin.risk.controlMeasures.vo.BizControlMeasuresRespVO;
import cn.iocoder.yudao.module.biz.controller.admin.risk.hazardResource.vo.BizHazardResourceRespVO;
import cn.iocoder.yudao.module.biz.dal.dataobject.risk.controlMeasures.BizControlMeasuresDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * 管控措施 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface BizControlMeasuresMapper extends BaseMapperX<BizControlMeasuresDO> {

    default PageResult<BizControlMeasuresDO> selectPage(BizControlMeasuresPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<BizControlMeasuresDO>()
                .eqIfPresent(BizControlMeasuresDO::getHazardSourceId,reqVO.getHazardSourceId())
                .orderByDesc(BizControlMeasuresDO::getId));
    }

    default List<BizControlMeasuresDO> selectList(BizControlMeasuresExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<BizControlMeasuresDO>()
                .eqIfPresent(BizControlMeasuresDO::getHazardSourceId,reqVO.getHazardSourceId())
                .orderByDesc(BizControlMeasuresDO::getId));
    }

    @Select("SELECT r.*,d.label control_type_name FROM biz_control_measures r\n" +
            "LEFT JOIN (SELECT value,label FROM system_dict_data  WHERE dict_type='control_type') d\n" +
            "ON r.control_type = d.value\n" +
            "WHERE r.hazard_source_id = #{hazardSourceId}")
    List<BizControlMeasuresRespVO> getControlMeasuresListByHazardId(String hazardSourceId);
}
